/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.pig4cloud.pigx.strategy.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.strategy.dto.StrategyContractAddDTO;
import com.pig4cloud.pigx.strategy.dto.StrategyContractEditDTO;
import com.pig4cloud.pigx.strategy.entity.StrategyContract;
import com.pig4cloud.pigx.strategy.service.StrategyContractService;
import com.pig4cloud.pigx.strategy.vo.StrategyContractVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 策略-合约
 *
 * @since 2022-11-24 10:39:27
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/contract")
@Api(value = "strategyContract", tags = "策略-合约管理")
public class StrategyContractController {

	private final StrategyContractService strategyContractService;

	/**
	 * 分页查询
	 *
	 * @param page      分页条件
	 * @param condition 查询条件
	 * @return {@link R< Page< StrategyContractVO>>}
	 * @since 2022/11/24 10:48
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@GetMapping("/page")
	public R<Page<StrategyContractVO>> page(Page<StrategyContract> page, StrategyContract condition) {
		return R.ok(strategyContractService.page(page, condition));
	}

	/**
	 * 根据id查询详情
	 *
	 * @param id id
	 * @return {@link R< StrategyContract>}
	 * @since 2022/11/24 11:21
	 */
	@ApiOperation(value = "通过id查询", notes = "通过id查询")
	@GetMapping("/{id}")
	public R<StrategyContract> getById(@PathVariable("id") Long id) {
		return R.ok(strategyContractService.getById(id));
	}

	/**
	 * 新增策略
	 *
	 * @param dto 数据
	 * @return {@link R< Object>}
	 * @since 2022/11/24 11:30
	 */
	@ApiOperation(value = "新增策略", notes = "新增策略")
	@SysLog("新增策略")
	@PostMapping
	public R<Object> add(@Validated @RequestBody StrategyContractAddDTO dto) {
		strategyContractService.add(dto);
		return R.ok();
	}

	/**
	 * 修改策略
	 *
	 * @param dto 数据
	 * @return {@link R< Object>}
	 * @since 2022/11/24 11:30
	 */
	@ApiOperation(value = "修改策略", notes = "修改策略")
	@SysLog("修改策略")
	@PutMapping
	public R<Object> edit(@Validated @RequestBody StrategyContractEditDTO dto) {
		strategyContractService.edit(dto);
		return R.ok();
	}

	/**
	 * 根据id逻辑删除
	 *
	 * @param id id
	 * @return {@link R< Object>}
	 * @since 2022/11/24 14:26
	 */
	@ApiOperation(value = "通过id删除策略", notes = "通过id删除策略")
	@SysLog("通过id删除策略")
	@DeleteMapping("/{id}")
	public R<Object> del(@PathVariable Long id) {
		strategyContractService.del(id);
		return R.ok();
	}

	/**
	 * 禁用策略
	 *
	 * @param id id
	 * @return {@link R< Object>}
	 * @since 2022/11/24 11:30
	 */
	@ApiOperation(value = "禁用策略", notes = "禁用策略")
	@SysLog("禁用策略")
	@PutMapping("/disable/{id}")
	public R<Object> disable(@PathVariable("id") Long id) {
		strategyContractService.disable(id);
		return R.ok();
	}

	/**
	 * 启用策略
	 *
	 * @param id id
	 * @return {@link R< Object>}
	 * @since 2022/11/24 11:30
	 */
	@ApiOperation(value = "启用策略", notes = "启用策略")
	@SysLog("启用策略")
	@PutMapping("/enable/{id}")
	public R<Object> enable(@PathVariable("id") Long id) {
		strategyContractService.enable(id);
		return R.ok();
	}

}
